package com.yuzhihao.writejvm.code;


import lombok.Data;

import java.util.*;

/**
 * @author yzh
 * @since 2021年12月16日14:57:15
 */
@Data
public class StackFrame{

    /**
     * 最大寄存数
     */
    private int maxpc;

    /**
     * pc寄存
     */
    private int pc;

    /**
     * 指令集
     */
    private Map<Integer,Operation> instructions = new TreeMap<>(Comparator.comparingInt(Integer::intValue));

    /**
     * 本地变量表
     */
    private Object[] lvs;

    /**
     * 操作数栈
     */
    private Stack<Object> stacks = new Stack<>();

    private StackFrame pre;

    public Operation next(){
        while (pc <= maxpc){
            Operation operation = instructions.get(pc);
            pc++;
            if(Objects.nonNull(operation)){
                return operation;
            }
        }
        return null;
    }

    public void setMaxpc(int maxpc) {
        this.maxpc = Math.max(maxpc,this.maxpc);
    }
}
